// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/MeshComponent.h"
#include "DeformMeshComponent.generated.h"

USTRUCT()
struct FDeformMeshSection
{
	GENERATED_BODY()

	UPROPERTY()
	UStaticMesh* StaticMesh;

	UPROPERTY()
	FMatrix DeformTransform;

	UPROPERTY()
	FBox SectionLocalBox;

	UPROPERTY()
	bool bSectionVisible;

	FDeformMeshSection()
		:SectionLocalBox(ForceInit),
		bSectionVisible(true)
	{}

	void Reset()
	{
		StaticMesh = nullptr;
		SectionLocalBox.Init();
		bSectionVisible = true;
	}
};

/**
 * 
 */
UCLASS()
class DEFORMMESH_API UDeformMeshComponent : public UMeshComponent
{
	GENERATED_BODY()
public:
	void CreateMeshSection(int32 SectionIndex, UStaticMesh* Mesh, const FTransform& DeformTransform);

	void UpdateMeshSectionTransform(int32 SectionIndex, const FTransform& DeformTransform);

	void FinishTransformsUpdate();

private:
	void UpdateLocalBounds();

private:
	UPROPERTY()
	TArray<FDeformMeshSection> DeformMeshSections;

	UPROPERTY()
	FBoxSphereBounds LocalBounds;

	friend class FDeformMeshSceneProxy;
};
